# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
import scrapy
from scrapy.pipelines.images import ImagesPipeline

class SsofaPipeline(ImagesPipeline):

    myheaders = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36',
    }
    
    def get_media_requests(self,item,info):
        for each in item['srcurl']:
            yield scrapy.Request(each,headers = self.myheaders,meta={'item':item})

    def file_path(self, request, response=None, info=None):
        image_guid = request.url.split("/")[-1].split('.')[0]
        path = "{}/{}.jpg".format(request.meta['item']['title'][0],image_guid)
        return path